﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Estimate.Common.DBFieldTypes;

namespace Estimate.Common.OldEstimate
{
    public class OldTableNameFactory
    {
        public static string GetOldTableName(string newTableName, DateTime dt,ForeSendpointType sendpoint)
        {
            string result = "";
            switch (newTableName)
            {
                case "Normal_CityFore":
                    if (sendpoint == ForeSendpointType.H10)
                    {
                        result = string.Format("Normal_{0}_10_CityFore", dt.ToString("yyyyMM"));
                    }
                    else
                    {
                        result = string.Format("Normal_{0}_CityFore", dt.ToString("yyyyMM"));
                    }
                    break;
                case "Zyt_CityFore":
                    result = string.Format("Zyt_{0}_CityFore",dt.ToString("yyyyMM"));
                    break;
                case "St_SiteFore":
                    result = string.Format("St_{0}_SiteFore",dt.ToString("yyyyMM"));
                    break;
                case "Sdx_CityFore":
                    result = string.Format("Sdx_{0}_CityFore",dt.ToString("yyyyMM"));
                    break;
                case "AutoRainReal":
                    result = string.Format("{0}_RainReal",dt.ToString("yyyy"));
                    break;
                case "AutoTempReal":
                    result = string.Format("{0}_TempReal",dt.ToString("yyyy"));
                    break;
                default:
                    result = "";
                    break;
            }
            return result;
        }

        public static string GetClockField(ForeClockType clock)
        {
            if (clock == ForeClockType.H08)
                return "08";
            else
                return "20";
        }

        public static string GetSpanField(ForeSpanType span)
        {
            string strSpan = span.ToString();
            string[] parts = strSpan.Replace("FD", "").Split(new char[] { '_' });
            int pre = Convert.ToInt32(parts[0]);
            int last = Convert.ToInt32(parts[1]);
            int value = 0;
            if (last % 24 == 0)
            {
                value = last;
            }
            else
            {
                value = last + 12;
            }
            if (value.ToString().Length == 2)
            {
                return "0" + value.ToString();
            }
            else
            {
                return value.ToString();
            }
            
        }

        public static string GetTypeField(ForeSpanType span, ForeFactorType factor)
        {
            if(factor == ForeFactorType.maxt || factor == ForeFactorType.mint)
                return factor.ToString();


            string strSpan = span.ToString();
            string[] parts = strSpan.Replace("FD", "").Split(new char[] { '_' });
            int pre = Convert.ToInt32(parts[0]);
            int last = Convert.ToInt32(parts[1]);
            if( (last-pre) == 24)
            {
                return factor.ToString();
            }
            else if (pre % 24 == 0)
            {
                return factor.ToString() + "1";
            }
            else
            {
                return factor.ToString() + "2";
            }
        }


    }
}
